//
//  HMStatuses.m
//  SinaWeiBo
//
//  Created by WGP on 16/4/13.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "HMStatuses.h"

@implementation HMStatuses

+(instancetype)statusWithDict:(NSDictionary *)dict
{
    id obj = [[self alloc] init];
    [obj setValuesForKeysWithDictionary:dict];
    
    return obj;
}


-(void)setValue:(id)value forUndefinedKey:(NSString *)key
{}

-(void)setValue:(id)value forKey:(NSString *)key
{
    if([key isEqualToString:@"user"])
    {
        _user = [HMUser userWithDict:value];
        return ;
    }
    
    if ([key isEqualToString:@"retweeted_status"]) {
        
        _retweeted_status = [HMStatuses statusWithDict:value];
        return ;
    }
    
    [super setValue:value forKey:key];
    
}


-(void)setPic_urls:(NSArray *)pic_urls
{
    _pic_urls = pic_urls;
    
    NSMutableArray *pic_urlsM = [NSMutableArray array];
    
    for (NSDictionary *dict in pic_urls) {
        
        NSURL *url = [NSURL URLWithString:dict[@"thumbnail_pic"]];
        [pic_urlsM addObject:url];
    }
    
    _pic_urlsArr = pic_urlsM.copy;
}

-(void)setSource:(NSString *)source
{
    if (![source isEqualToString:@""]) {
        NSMutableString *newSource = [NSMutableString stringWithString:source];
        NSRange firstRange = [newSource rangeOfString:@"\">"];
        
        NSString *firstStr = [newSource substringToIndex:firstRange.location+firstRange.length];
        
        [newSource replaceOccurrencesOfString:firstStr withString:@"来自 " options:0 range:NSMakeRange(0, newSource.length)];
        [newSource replaceOccurrencesOfString:@"</a>" withString:@"" options:0 range:NSMakeRange(0, newSource.length)];
        _source = newSource;
    }
}

@end








